/*
 * @Descripttion:调用后端商品接口的函数
 */

import axios from 'axios'

// 读商品详情
const showProduct = id =>
	axios.get('/api/test/shop/commodity', {
		params: {
			id: id,
		},
	})
	.then(res => res.data)

// 读取商品列表
const listProducts = (nowPage, pageSize) =>
	axios.get('/api/test/shop/commodity/all', {
		params: {
			nowPage: nowPage,
			pageSize: pageSize,
		},
	})
	.then(res => res.data)

// 推荐商品
const recommend = () =>
	axios.get('/api/test/shop/commodity/all', {
		params: {
			nowPage: 1,
			pageSize: 7,
		},
	})
	.then(res => res.data)

//读取商品的图片
const showPictures = id => axios.get('/api/test/imgs/${id}').then(res => res.data)

// //搜索商品
// const searchProducts = form =>
//   axios.post('/api/test/searches', form).then(res => res.data)

// 分类获取
const listProductsWithCategory = (type, nowPage, pageSize) => {
	console.log("xxxx");
	if (type == ''){
		
		return listProducts(nowPage, pageSize)
	}
	else
		return axios.get('/api/test/shop/category', {
				params: {
					type: type,
					nowPage: nowPage,
					pageSize: pageSize,
				},
			})
			.then(res => res.data)
}


// // 排行榜详情
// const showRanking = () => axios.get('/api/v1/ranking/').then(res => res.data)

export {
	showProduct,
	listProducts,
	showPictures,
	recommend,
	listProductsWithCategory,
	// searchProducts,
	// showRanking
}
